﻿using Projet_IMA.Base;
using Projet_IMA.Habillage.Material;
using Projet_IMA.Object3D;
using Projet_IMA.Unsafe;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Projet_IMA.Environnement
{
    public class SceneRepere
    {
        private int longeur;
        private List<CachePoint> cacheRepere;
        private Scene3D scene;

        public SceneRepere(Scene3D scene,int longeur)
        {
            this.cacheRepere = new List<CachePoint>();
            this.longeur = longeur;
            this.scene = scene;
            this.MakeCache();
        }

        private void MakeCache()
        {  
            MaterialFixedColor m1 = new MaterialFixedColor(new Couleur(1, 0, 0));
            MaterialFixedColor m2 = new MaterialFixedColor(new Couleur(0, 1, 0));
            MaterialFixedColor m3 = new MaterialFixedColor(new Couleur(0, 0, 1));
            scene.AddMaterial(m1);
            scene.AddMaterial(m2);
            scene.AddMaterial(m3);

            cacheRepere.Add((new Ligne(new V3(0, 0, 0), new V3(1, 0, 0), longeur, new Couleur(1, 0, 0), 1.0F).GetCache()));
            cacheRepere.Add((new Triangle(new V3(longeur, 7, 7), new V3(longeur, -7, -7), new V3(longeur + 12, 0, 0), m1, 0.003F).GetCache()));
            
            cacheRepere.Add((new Ligne(new V3(0, 0, 0), new V3(0, 1, 0), longeur, new Couleur(0, 1, 0), 1.0F).GetCache()));
            cacheRepere.Add((new Triangle(new V3(7, longeur, 7), new V3(-7, longeur, -7), new V3(0, longeur + 12, 0), m2, 0.003F).GetCache()));
            
            cacheRepere.Add((new Ligne(new V3(0, 0, 0), new V3(0, 0, 1), longeur, new Couleur(0, 0, 1), 1.0F).GetCache()));
            cacheRepere.Add((new Triangle(new V3(7, 7, longeur), new V3(-7, -7, longeur), new V3(0, 0, longeur + 12), m3, 0.003F).GetCache()));
        }

        private void ClearCache()
        {
            foreach (CachePoint cache in this.cacheRepere)
            {
                cache.Reset();
            }
            cacheRepere.Clear();
        }

        public List<CachePoint> GetCacheRepere()
        {
            return cacheRepere;
        }

        public void Decreases()
        {
            longeur -= 20;
            if (longeur < 20) longeur = 20;

            ClearCache();
            MakeCache();
        }

        public void Increases()
        {
            longeur += 20;

            ClearCache();
            MakeCache();
        }
    }
}
